﻿using Castle.DynamicProxy;

using PLCS.Client.IService.Attributes;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace PLCS.Client.IService
{
    public class LogShowInterceptor : StandardInterceptor
    {
        protected override void PerformProceed(IInvocation invocation)
        {
            MethodInfo? method = invocation.Method;
            Action<IInvocation> action = (invocation) => base.PerformProceed(invocation);
            if (method.IsDefined(typeof(LogAttribute), true))
            {
                var attribute = method.GetCustomAttributes(typeof(LogAttribute), true)
                                     .FirstOrDefault() as LogAttribute;

                if (attribute != null)
                {
                    var a = method.Module.Name;
                    ParameterInfo[] parameters = method.GetParameters();

                    var parameterslist = new Dictionary<string, string>();

                    foreach (ParameterInfo parameter in parameters)
                    {
                        string name = parameter.Name;
                        Type parameterType = parameter.ParameterType;

                        parameterslist.Add(name, parameterType.Name);
                    }
                    string MethodName = method.Name;
                    attribute.AOPAction(invocation, action);
                }
            }
        }
    }
}